package com.hengtuo.student.test;

import javax.transaction.Transactional;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;

import com.hengtuo.student.pojo.User;




@SuppressWarnings("deprecation")
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:spring/spring-mvc.xml",  
"classpath:spring/spring-hibernate.xml" })  
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)  
@Transactional  
public class testSessionFactory {
	@Autowired
	private SessionFactory sf;
	@Test
	public void test() {
//		ApplicationContext ac = new ClassPathXmlApplicationContext("spring/spring-hibernate.xml");
//		SessionFactory sf=(SessionFactory) ac.getBean("sessionFactory");
		Session session = sf.getCurrentSession();
		User u = new User();
		sf.getCurrentSession().save(u);
	}
}
